#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>

int main()
{
    int pipefd[2];
    if(pipe(pipefd)== -1)
    {
        perror("fail to pipe");
        exit(-1);
    }
    printf("pipefd[0] = %d\npipefd[1] = %d\n",pipefd[0],pipefd[1]);

    if(write(pipefd[1],"hello world",12)==-1)
    {
        perror("fail to write");
        exit(-1);
    }
    char buf[32] = "";
    ssize_t bytes = 0;
    if((bytes = read(pipefd[0],buf,12))==-1)
    {
        perror("fail to read");
        exit(-1);
    }
    printf("bytes = %ld\n",bytes);
    printf("buf = %s\n",buf);
    if((bytes = read(pipefd[0],buf,12))==-1)
    {
        perror("fail to read");
        exit(-1);
    }
    printf("bytes = %ld\n",bytes);
    printf("buf = %s\n",buf);
    return 0;
}